﻿using System.Collections.Generic;
using System.IO.IsolatedStorage;
using Mal.WP7.TimeClock.Models;

namespace Mal.WP7.TimeClock.Repositories
{
    public class Repository
    {
        #region Fields
        private const string RepositoryKey = "RepositoryKey";
        private static Repository instance;
        private List<TimeClockDay> datas;
        #endregion

        #region Construction / Destruction
        private Repository()
        {   
            if (!IsolatedStorageSettings.ApplicationSettings.Contains(Repository.RepositoryKey))
            {
                IsolatedStorageSettings.ApplicationSettings[Repository.RepositoryKey] = new List<TimeClockDay>();
            }

            IsolatedStorageSettings.ApplicationSettings.Save();

            this.datas = (List<TimeClockDay>)IsolatedStorageSettings.ApplicationSettings[Repository.RepositoryKey];
        }
        #endregion

        #region enum, struct, class

        #endregion

        #region Properties
        public static Repository Instance
        {
            get
            {
                if (Repository.instance == null)
                {
                    Repository.instance = new Repository();
                }

                return Repository.instance;
            }
        }

        public List<TimeClockDay> Datas
        {
            get
            {
                return this.datas;
            }

            private set
            {
                this.datas = value;
            }
        }
        #endregion

        #region Methods
        public void Save()
        {
            //IsolatedStorageSettings.ApplicationSettings[Repository.RepositoryKey] = this.Datas;

            IsolatedStorageSettings.ApplicationSettings.Save();
        }
        #endregion

        #region Events

        #endregion
    }
}
